package com.air.ota.vo;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import com.air.ota.mo.RegTrans;
import com.air.ota.util.ConfigProperties;
import com.air.ota.util.HexStringUtil;

public class SZTRegReqTransVO extends SZTBaseReqTransVO {
	
	
	public SZTRegReqTransVO( byte[] deviceSequence,byte[] sztSequence,String deviceTriggerTime,RegTrans trans) throws Exception{
		
		super(deviceSequence,sztSequence,deviceTriggerTime);
		
		this.cardAppSequence = HexStringUtil.hexStringToBytes(trans.getCardAppSequence());
		this.random = HexStringUtil.hexStringToBytes(trans.getCardRandom());
		this.lastTransData = HexStringUtil.hexStringToBytes(trans.getLastTransData());
		this.deposit = HexStringUtil.hexStringToBytes(trans.getCardDeposit());
		this.sumDeviceTransFee = HexStringUtil.hexStringToBytes("00000000");
		this.sumCardDepositFee = HexStringUtil.hexStringToBytes(trans.getCardSumDeposit());
		
		this.cardSamId = Arrays.copyOfRange(this.samId, 0, 4);
		
		this.transTypeCode = 0x01;
		this.subTransTypeCode = 0x12;
		this.tranAppendCode = 0x01;
		this.fee = HexStringUtil.hexStringToBytes("00000000");
		
		this.remain = HexStringUtil.hexStringToBytes(trans.getCardRemain());
		this.cardTransSequence = HexStringUtil.hexStringToBytes(trans.getRegSequence());
		
		
		this.startDate =trans.getCardEffectTime();
		this.endDate = trans.getCardExpireTime();
		
		this.samCardTransSequence = HexStringUtil.hexStringToBytes("00000000");
		this.cardType = HexStringUtil.hexStringToBytes(trans.getCardType())[0];
		
		
		
		this.transData  = makeTransData();
	}
	
	
	private byte[] cardAppSequence;
	private byte[] random;
	private byte[] lastTransData;
	private byte[] deposit;
	private byte[] fee;
	private byte[] remain;
	private byte[] cardTransSequence;
	private byte[] sumDeviceTransFee;
	private String startDate;
	private String endDate;
	private byte[] sumCardDepositFee;
	private byte[] samCardTransSequence;
	private byte[] cardSamId;
	private byte cardType;
	
	public byte[] makeTransData(){
		StringBuffer hexStringBuf = new StringBuffer();
		
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.cardAppSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.random));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.lastTransData));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.deposit));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.fee));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.remain));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.cardTransSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.sumDeviceTransFee));
		hexStringBuf.append(startDate);
		hexStringBuf.append(endDate);
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.sumCardDepositFee));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.samCardTransSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.cardSamId));
		hexStringBuf.append(HexStringUtil.byteToHexString(this.cardType));
		
		
		return HexStringUtil.hexStringToBytes(hexStringBuf.toString());
	}
	
	
	
	
}
